package com.gm.camunda.service.impl;

import com.gm.camunda.entity.TaskEntity;
import com.gm.camunda.service.ProcessTaskService;
import com.gmadmin.utils.CollectionBeanUtils;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.task.Task;

import java.util.List;

/**
 * {@code @Author}: zhang liang
 * {@code @Date}: 2022/10/9 20:07
 * {@code @BelongsProject}: gm
 * {@code @BelongsPackage}: com.gm.camunda.service.impl
 * {@code @Description}: 流程任务实现
 */

public class ProcessTaskServiceImpl implements ProcessTaskService {

    private final TaskService taskService;
    private final IdentityService identityService;
    private final RuntimeService runtimeService;
    private final HistoryService historyService;

    public ProcessTaskServiceImpl(TaskService taskService, IdentityService identityService, RuntimeService runtimeService, HistoryService historyService) {
        this.taskService = taskService;
        this.identityService = identityService;
        this.runtimeService = runtimeService;
        this.historyService = historyService;
    }

    @Override
    public List<TaskEntity> queryUserToDo(String userId) {
        List<Task> tasks = taskService.createTaskQuery().taskAssignee(userId).list();
        return CollectionBeanUtils.copyListProperties(tasks, TaskEntity::new);
    }

    @Override
    public void taskPass(String taskId) {
        taskService.complete(taskId);
    }
}
